package com.soap.call;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import android.content.Context;
import android.text.TextUtils;

import com.Utility.Base64;
import com.Utility.Configs;
import com.Utility.Utility;
import com.objects.VaultFile;
import com.parser.Error_Report;

public class Http_Soap_Call {

	private String Url;
	private String line;
	Context ctxt;
	HttpPost httppost = new HttpPost(Configs.API_BASE_URL);

	/**
	 * @param String
	 *            Url
	 * @param Context
	 *            cts
	 * @return factory object
	 */
	public static Http_Soap_Call create_connection(String Url, Context cts) {

		if (!check_network.isNetworkAvailable(cts)) {

			return null;
		} else {
			return new Http_Soap_Call(Url, cts);
		}

	}

	public static Http_Soap_Call create_offline(String Url, Context cts) {

		return new Http_Soap_Call(Url, cts);

	}

	private Http_Soap_Call(String Url, Context cts) {
		this.Url = Url;
		ctxt = cts;

	}

	public InputStream GetIsLoginTokenValid(String Token, String renew,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>"
				+ " <GetIsLoginTokenValid  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + Token + "</Token>" + "   <renew>" + renew
				+ "</renew>  " + "  </GetIsLoginTokenValid> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetIsLoginTokenValid");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	/**
	 * call http connection for authorization.
	 * 
	 * @param repor
	 * 
	 * @param String
	 *            email
	 * @param String
	 *            password
	 * @return input stream after authorization email and password
	 */
	public InputStream GetLoginToken(String username, String password,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetLoginToken xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <UserName>" + username + "</UserName>" + "   <Password>"
				+ password + "</Password>  "
				+ " <ApplicationName>SenditCertified-Android</ApplicationName>"
				+ "  </GetLoginToken> " + " </soap:Body>" + "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetLoginToken");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetDeliveryAcceptance(String username, String password,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetDeliveryAcceptance  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + username + "</Token>" + "   <msg_guid>"
				+ password + "</msg_guid>  " + "  </GetDeliveryAcceptance> "
				+ " </soap:Body>" + "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetDeliveryAcceptance");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream RequestAccessCode(String username, String password,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <RequestAccessCode  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + username + "</Token>" + "   <msg_guid>"
				+ password + "</msg_guid>  " + "  </RequestAccessCode> "
				+ " </soap:Body>" + "</soap:Envelope>";

		System.out.println("Request  " + SOAPRequestXML);

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/RequestAccessCode");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetEPackageError(String username, String password,
			String AccessCode, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		if (AccessCode != null && AccessCode.length() == 0) {
			AccessCode = "123456";
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetEPackageError  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + username + "</Token>" + "   <msg_guid>"
				+ password + "</msg_guid>  " + "   <AccessCode>" + AccessCode
				+ "</AccessCode>  " + "  </GetEPackageError> "
				+ " </soap:Body>" + "</soap:Envelope>";

		try {
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			System.out.println("Request" + SOAPRequestXML);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetEPackageError");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetEPackage(String username, String password,
			String AccessCode, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetEPackage  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + username + "</Token>" + "   <msg_guid>"
				+ password + "</msg_guid>  " + "   <AccessCode>" + AccessCode
				+ "</AccessCode>  " + "  </GetEPackage> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetEPackage");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetUploadFileResponse(String token, String fileName,
			byte[] array, long offset, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		if (!TextUtils.isEmpty(fileName)) {
			fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
		}
		String base64 = Base64.encodeBytes(array);

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "";
		try {
			SOAPRequestXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
					+ "<soapenv:Header/>"
					+ "<soapenv:Body>"
					+ "<priv:UploadFileToVault_Ext>"
					+ "<priv:Token>"
					+ token
					+ "</priv:Token>"
					+ "<priv:FileName>"
					+ fileName
					+ "</priv:FileName>"
					+ "<priv:bytearray>"
					+ base64
					+ "</priv:bytearray>"
					+ "<priv:Offset>"
					+ offset
					+ "</priv:Offset>"
					+ "</priv:UploadFileToVault_Ext>"
					+ "</soapenv:Body>" + "</soapenv:Envelope>";
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			System.out.println("Upload Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/UploadFileToVault_Ext");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();EntityUtils.toString(responseEntity);
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetLoginToken_Expire(String token, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <InvalidateLoginToken  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + token + "</Token>"
				+ "  </InvalidateLoginToken> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/InvalidateLoginToken");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetFile(String token, String message_id, String filepos,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetFile  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + token + "</Token>" + "  <msg_guid>"
				+ message_id + "</msg_guid>" + "  <filepos>" + filepos
				+ "</filepos>" + "  </GetFile> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetFile");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	/**
	 * 
	 * @return
	 */

	public InputStream CopyFileToVault(String token, String message_id,
			String filepos, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <CopyFileToVault  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + token + "</Token>" + "  <msg_guid>"
				+ message_id + "</msg_guid>" + "  <filepos>" + filepos
				+ "</filepos>" + "  </CopyFileToVault> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/CopyFileToVault");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetWebInterfaceURL(String token,
			String WebInterfaceType, String message_id, String filepos,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>   "
				+ " <GetWebInterfaceURL  xmlns=\"https://www.privacydatasolutions.net/\">    "
				+ "  <Token>" + token + "</Token>" + "  <msg_guid>"
				+ message_id + "</msg_guid>" + "  <WebInterfaceType>"
				+ WebInterfaceType + "</WebInterfaceType>" + "  <filepos>"
				+ "</filepos>" + " </GetWebInterfaceURL> " + " </soap:Body>"
				+ "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetWebInterfaceURL");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetTime() {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?> "
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body> "
				+ "   <GetTime xmlns=\"https://www.privacydatasolutions.net/\" /> "
				+ " </soap:Body>" + "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetTime");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetUser(String username, String password,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
				+ "  <soap:Body>  "
				+ "  <GetUser xmlns=\"https://www.privacydatasolutions.net/\"> "
				+ "     <cUserName>" + username + "</cUserName>  "
				+ "    <cPassword>" + password + "</cPassword>  "
				+ "  </GetUser>" + "  </soap:Body>" + "</soap:Envelope>";

		try {
			Utility.printLog("GetUser request", SOAPRequestXML);
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetUser");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream GetUserSecurityImage(String username, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
				+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
				+ "  <soap:Body>  "
				+ "  <GetUserSecurityImage  xmlns=\"https://www.privacydatasolutions.net/\"> "
				+ "     <UserName>" + username + "</UserName>  "
				+ "  </GetUserSecurityImage>" + "  </soap:Body>"
				+ "</soap:Envelope>";

		try {
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetUserSecurityImage");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity + ""
					+ httpResponse.getStatusLine().getStatusCode());
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			e.printStackTrace();
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			ste.printStackTrace();
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			e.printStackTrace();
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
			repor.setMessage("Network IllegalResponce");
		}
		return in;
	}

	public InputStream GetUserInbox(String Token, String OnlyNewMessages,
			String Month, String Year, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "
				+ " <soap:Body>"
				+ "<GetUserInbox xmlns=\"https://www.privacydatasolutions.net/\"> "
				+ "     <Token>"
				+ Token
				+ "</Token>  "
				+ "    <OnlyNewMessages>"
				+ OnlyNewMessages
				+ "</OnlyNewMessages>   "
				+ "   <Month>"
				+ Month
				+ "</Month>     "
				+ " <Year>"
				+ Year
				+ "</Year> "
				+ "   </GetUserInbox> " + " </soap:Body>" + "</soap:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetUserInbox");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public InputStream DeletwVaultFiles(String Token, String files,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
				+ "<soapenv:Header/>"
				+ "<soapenv:Body>"
				+ "<priv:DeleteFilesFromVault>"
				+ "<priv:Token>"
				+ Token
				+ "</priv:Token>"
				+ " <priv:Files>"
				+ files
				+ "</priv:Files>"
				+ "</priv:DeleteFilesFromVault>"
				+ "</soapenv:Body>"
				+ "</soapenv:Envelope>";

		try {
			System.out.println("GetVaultCatalog Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/DeleteFilesFromVault");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public String readResponse(InputStream in) // read xml response
	{
		int BUFFER_SIZE = 2000;
		int charRead;

		InputStreamReader isr = new InputStreamReader(in);
		System.out.println("response stream in read respone=" + in);
		String str = "";
		char[] inputBuffer = new char[BUFFER_SIZE];
		try {
			while ((charRead = isr.read(inputBuffer)) > 0) {
				// ---convert the chars to a String---
				String readString = String
						.copyValueOf(inputBuffer, 0, charRead);
				str += readString;
				inputBuffer = new char[BUFFER_SIZE];
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("response from server=" + str);
		return str;
	}

	public String deleteFilesFromVault(String token,
			ArrayList<VaultFile> files, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		String result = null;

		StringBuffer fnames = new StringBuffer();
		for (int i = 0; i < files.size(); i++) {
			fnames.append(files.get(i).getName());
			if (i != files.size() - 1)
				fnames.append(",");
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
				+ "<soapenv:Header/>"
				+ "<soapenv:Body>"
				+ "<priv:DeleteFilesFromVault>"
				+ "<priv:Token>"
				+ token
				+ "</priv:Token>"
				+ "<priv:Files>"
				+ fnames.toString()
				+ "</priv:Files>"
				+ "</priv:DeleteFilesFromVault>"
				+ "</soapenv:Body>" + "</soapenv:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/DeleteFilesFromVault");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			result = String.valueOf(httpResponse.getStatusLine()
					.getStatusCode());

			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			// in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		/*
		 * try { return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); } return in;
		 */
		return result;
	}

	public InputStream downloadFilesFromVault(String token, String fileName,
			long offset, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
				+ "<soapenv:Header/>"
				+ "<soapenv:Body>"
				+ "<priv:GetFileFromVault_Ext>"
				+ "<priv:Token>"
				+ token
				+ "</priv:Token>"
				+ "<priv:filename>"
				+ fileName
				+ "</priv:filename>"
				+ "<priv:Offset>"
				+ offset
				+ "</priv:Offset>"
				+ "</priv:GetFileFromVault_Ext>"
				+ "</soapenv:Body>" + "</soapenv:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetFileFromVault_Ext");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}

		/*
		 * try { return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		return in;
	}

	public InputStream getDownloadFilesSize(String token, String fileName,
			Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
				+ "<soapenv:Header/>"
				+ "<soapenv:Body>"
				+ "<priv:GetFileSizeFromVault>"
				+ "<priv:Token>"
				+ token
				+ "</priv:Token>"
				+ "<priv:filename>"
				+ fileName
				+ "</priv:filename>"
				+ "</priv:GetFileSizeFromVault>"
				+ "</soapenv:Body>" + "</soapenv:Envelope>";

		try {
			System.out.println("Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/GetFileSizeFromVault");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			HttpEntity responseEntity = httpResponse.getEntity();
			System.out.println("responseEntity=" + responseEntity);
			in = responseEntity.getContent();
		} catch (ConnectTimeoutException e) {
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}

		try {
			return new ByteArrayInputStream(readResponse(in).getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return in;
	}

	public String GetUploadMediResponse(String token, String fileName,
			byte[] array, long offset, Error_Report repor) {
		if (!check_network.isNetworkAvailable(ctxt)) {

			return null;
		}
		HttpEntity responseEntity = null;

		if (!TextUtils.isEmpty(fileName)) {
			fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
		}
		String base64 = Base64.encodeBytes(array);

		InputStream in = null;
		int timeoutConnection = 10000;
		HttpParams httpParameters = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(httpParameters,
				timeoutConnection);
		int timeoutSocket = 10000;
		HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
		HttpClient httpclient = new DefaultHttpClient(httpParameters);

		String SOAPRequestXML = "";
		try {
			SOAPRequestXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:priv=\"https://www.privacydatasolutions.net/\">"
					+ "<soapenv:Header/>"
					+ "<soapenv:Body>"
					+ "<priv:UploadMediaToServer_Ext>"
					+ "<priv:Token>"
					+ token
					+ "</priv:Token>"
					+ "<priv:FileName>"
					+ fileName
					+ "</priv:FileName>"
					+ "<priv:bytearray>"
					+ base64
					+ "</priv:bytearray>"
					+ "<priv:Offset>"
					+ offset
					+ "</priv:Offset>"
					+ "</priv:UploadMediaToServer_Ext>"
					+ "</soapenv:Body>" + "</soapenv:Envelope>";
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			System.out.println("Upload Request" + SOAPRequestXML);
			StringEntity se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
			se.setContentType("text/xml");
			httppost.setHeader("Content-Type", "text/xml");
			httppost.setHeader("SOAPAction",
					"https://www.privacydatasolutions.net/UploadMediaToServer_Ext");
			httppost.setEntity(se);
			BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient
					.execute(httppost);
			System.out.println("httpResponse=" + httpResponse.getStatusLine());
			responseEntity = httpResponse.getEntity();
		} catch (ConnectTimeoutException e) {
			// Log.e("Timeout Exception: ", e.toString());
			repor.setMessage("Request Timeout");
		} catch (SocketTimeoutException ste) {
			repor.setMessage("Request Timeout");
		} catch (Exception e) {
			repor.setMessage("Network Timeout");
		}
		/*
		 * try{ return new
		 * ByteArrayInputStream(readResponse(in).getBytes("UTF-8")); } catch
		 * (Exception e) { e.printStackTrace(); }
		 */
		if (responseEntity != null) {
			try {
				return EntityUtils.toString(responseEntity, "utf-8");
			} catch (Exception e) {
				return null;
			}
		}
		return null;
	}

}
